using System;



namespace Framework.Network
{
    public abstract class BaseMessageHandler<Message> : IMessageHandler where Message : class
    {
        protected abstract FTask Run(Session session, Message message);

        public async FVoid Handle(Session session, object msg)
        {
            Message message = msg as Message;
            if (message == null)
            {
                Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof(Message).Name}");
            }
            try
            {
                await this.Run(session, message);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }

        public Type GetMessageType()
        {
            return typeof(Message);
        }
    }
}